import sun.applet.AppletAudioClip;

import javax.swing.*;
import java.applet.AudioClip;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * @classname 开始界面绘制
 * @Author 姬如千泷
 * @Date 2021/4/29  17:13
 * @Version 1.0
 */
public class Main implements ActionListener {//开始主类
    Frame frame = new Frame();//开始屏幕
    JLabel label = new JLabel(DateCenter.beginPanel);//背景标签
    MyButton button = new MyButton(300,150,200,80,DateCenter.beginGame);//开始游戏按钮
    AudioClip background_voice = new AppletAudioClip(DateCenter.background_voiceUrl);
    public static void main(String[] args) {
        new Main().init();
    }
    public void init(){
        background_voice.loop();
        frame.setBounds(600,200,800,530);
        frame.setTitle("Lin的大冒险1.1.1");
        frame.setLayout(null);
        label.setBounds(0,30,800,530);
        frame.add(label);
        frame.addWindowListener(new WindowAdapter() {//适配器模式检测窗口监听
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        button.addActionListener(this);
        frame.add(button,0);
        frame.setResizable(false);
        frame.setVisible(true);
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        new Thread(()->{
            int k = 150;
            for (int i = 0; i < 5; i++) {//开始游戏按钮动态上移消失
                button.setLocation(300,k);
                k-=50;
                try {
                    Thread.sleep(200);
                } catch (InterruptedException interruptedException) {
                    interruptedException.printStackTrace();
                }
                frame.repaint();
            }
            frame.dispose();
            new MyLoad(0);
        }).start();
    }
}
class MyButton extends JButton{
    public MyButton(int x,int y,int w,int h,ImageIcon i) {//设置一个图标按钮
        setActionCommand("开始游戏");
        setBounds(x,y,w,h);
        setIcon(i);
        //设定透明效果
        setOpaque(false);
        //去掉背景点击效果
        setContentAreaFilled(false);
        // 去掉聚焦线
        setFocusPainted(false);
        // 去掉边框
        this.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(DateCenter.mouse, new Point(16, 16), "mycursor"));
        setBorder(null);
    }
}
